<?php
namespace app\mobile\controller;

use app\model\Theme; 
use app\model\Poster; 
use app\model\Worker; 

class WSetbase extends Base
{
    public function W_setbase()
    {
global $_G, $_P;
$fans = $this->checkuser();
$themeid = intval($_P['themeid']);
if($themeid < 0){
	return_msg('管理后台地址不正确');
}
$system=$_G['system'];
$theme = Theme::getThemeById($themeid);
$config = 	Theme::getConfig($themeid);
if(empty($theme['id'])){
	return_msg('管理后台地址不正确');
}
$myworker = Worker::getThemeWorkerByOpenidNew($_G['openid'],$themeid);
if(!($system['ruanjian']!=3 || $config['showshop']==0 || ($system['ruanjian']==3 && $config['showshop']==$myworker['company']))){
	$myworker = "";
}
if (empty($myworker)) {
	return_msg('您不是员工,无权访问');
}
$msg = Worker::gethoutaistats();
if (!empty($msg)) {
	return_msg($msg);
}
$do = 'order';
$op = !empty($_P['op']) ? $_P['op'] : 'display';
$id = intval($_P['id']);

if ($op=='display') {
    if ($config['zhuandanbegintime']<strtotime("2019-01-01")) {
    	$config['zhuandanbegintime'] = $theme['endtime'];
    }
    if ($config['zhuandanendtime']<strtotime("2019-01-01")) {
    	$config['zhuandanendtime'] = $theme['endtime'];
    }
}elseif ($op=='save'){

	if (empty($_P['title']) || empty($_P['desc'])) {
		return_msg('活动主标题、副标题均不可为空');
	}

		$words=explode(",",$system['s']['adkeyword']);
		$res_banned1=Poster::check_words($words,$_P['title']);
		if (!empty($res_banned1)) {
			return_msg('主标题含有违规词：'.implode(',',$res_banned1));
		}
		$res_banned2=Poster::check_words($words,$_P['desc']);
		if (!empty($res_banned2)) {
			return_msg('副标题含有违规词：'.implode(',',$res_banned2));
		}

	$data = array (
		'title'       => $_P['title'],
		'desc'        => $_P['desc'],
		'mobile'      => $_P['mobile'],
		'endtime'     => strtotime($_P['endtime'])+59,
		'status'      => intval($_P['status']),
	);
	$theme_old = array(
		'title'       => $theme ['title'],
		'desc'        => $theme ['desc'],
		'mobile'      => $theme ['mobile'],
		'endtime'     => $theme ['endtime'],
		'status'      => $theme ['status'],
	);
	writelog($id,'手机编辑',$theme_old,$data,$myworker['username']);
    Theme::update($themeid,$data);
    $config_old = $config;

	$config['joinfee'] = sprintf("%.2f",floatval($_P['joinfee']));
	$config['renshu'] = intval($_P['renshu']);


	$config['groupprice'] = sprintf("%.2f",floatval($_P['groupprice']));
	$config['primeprice'] = sprintf("%.2f",floatval($_P['primeprice']));
	$config['marketprice'] = sprintf("%.2f",floatval($_P['marketprice']));
	$config['groupprice'] = sprintf("%.2f",floatval($_P['groupprice']));
	$config['groupprice2'] = sprintf("%.2f",floatval($_P['groupprice2']));
	$config['joinfee2'] = sprintf("%.2f",floatval($_P['joinfee2']));
	$config['joinfee3'] = sprintf("%.2f",floatval($_P['joinfee3']));

	$config['duojiagetips'] = $_P['duojiagetips'];
	$config['joinname'] = $_P['joinname'];
	$config['joinname2'] = $_P['joinname2'];
	$config['joinname3'] = $_P['joinname3'];
	$config['maxcountall'] = intval($_P['maxcountall']);
	$config['maxcountall2'] = intval($_P['maxcountall2']);
	$config['tuanmode'] = intval($_P['tuanmode']);
	$config['addresstxt'] = $_P['addresstxt'];
	$config['zhuandantxt'] = $_P['zhuandantxt'];
	$config['zhuandanbegintime'] = strtotime($_P['zhuandanbegintime']);
	$config['zhuandanendtime'] = strtotime($_P['zhuandanendtime']);
	$config['zhuandantips'] = $_P['zhuandantips'];

	writelog($id,'手机编辑',$config_old,$config,$myworker['username']);
	Theme::setConfig($config,$themeid,$_G['mpid']);
    return_msg('更新成功','','success');
}
    
if($_G['companyname'] =='新飞驰软件'){
	$return_clicent = get_defined_vars();
return view('/fcworker/fc_setbase' , $return_clicent);
}else{
	$return_clicent = get_defined_vars();
return view('/yxworker/w_setbase' , $return_clicent);
}
}
}